1711C - Color the Picture - CodeForces Solution


constructive algorithms greedy *1500

Please click on ads to support us..

Python Code:

import math as mt
from collections import defaultdict,deque
from bisect import bisect_left as b_l
from bisect import bisect_right as b_r
import sys

mod=10**9+7


for _ in range(int(input())):
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    if(n==1 or m==1):
        print("No")
        continue
    else:
        a.sort(reverse=True)

        total=m
        if(total&1):flag=False
        else:flag=True
        for i in a:
            if(total&1):
                if((i//n)>=3):
                    flag=True
            if((i//n)>1):
                total-=(i//n)
        if(total<=0 and flag):
            print("Yes")
            continue

        total=n
        if(total&1):flag=False
        else:flag=True
        for i in a:
            if(total&1):
                if((i//m)>=3):
                    flag=True
            if((i//m)>1):
                total-=(i//m)
        if(total<=0 and flag):
            print("Yes")
            continue

        print("No")
            

C++ Code:

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    for (int test=0;test<t;test++)
    {
        ll n,m,k;
        cin>>n>>m>>k;
        ll am =0;
        bool am1=false;
        ll an =0;
        bool an1=false;
        for(int i=0;i<k;i++)
        {
            ll ai;
            cin>>ai;
            ll amm = ai/n;
            if(amm>1)
            {
                am+=amm;
            }
            am1 = am1 || (amm>2);
            ll ann = ai/m;
            if(ann>1)
            {
                an+=ann;
            }
            an1 = an1 || (ann>2);
        }
        cout<<(((am>=m && (am1 || m%2==0)) || (an>=n && (an1 || n%2==0)))?"Yes":"No")<<endl;

    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules